package com.lyf.learn.atsgg.spring.jdbctemplate.dao;

import com.lyf.learn.atsgg.spring.ioc.bean.UserBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.LinkedList;
import java.util.List;

/**
 * @AUTHOR LYF
 * @DATE 2022/5/26
 * @VERSION 1.0
 * @DESC
 */
@Repository
public class JdbcTestDaoImpl implements JdbcTestDao{
    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public void addUser() {
        //jdbcTemplate.
        jdbcTemplate.execute("INSERT INTO user(user_id,user_name,password,email) VALUE('TestUser','Lyf123','123321','674619459') ");
        jdbcTemplate.batchUpdate();
    }

    @Override
    public void deleteUserById(Integer id) {
        String sql= "DELETE FROM user WHERE id = ?";
        jdbcTemplate.update(sql,id);
    }

    @Override
    public void query() {
        String sql  = "";
        int n = jdbcTemplate.queryForObject(sql,Integer.class);
        jdbcTemplate.query(sql,new BeanPropertyRowMapper<>());
    }

    @Override
    public void batchOpt() {
        String sql  ="";
        Object[]o1 = {};
        List list = new LinkedList<>();
        jdbcTemplate.batchUpdate(sql,list);
    }
}
